PDF export printing in Internet Explorer [closed]
        Posted  
        
            by 
                user619804
            
        on Programmers
        
        See other posts from Programmers
        
            or by user619804
        
        
        
        Published on 2012-11-23T19:04:00Z
        Indexed on 
            2012/11/23
            23:21 UTC
        
        
        Read the original article
        Hit count: 308
        
java
|JavaScript
protected static byte[] exportReportToPdf(JasperPrint jasperPrint) 
                                                      throws JRException {
  JRPdfExporter exporter = new JRPdfExporter();       
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
  exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, baos);
  exporter.setParameter(JRPdfExporterParameter.PDF_JAVASCRIPT, 
              "this.print({bUI: true,bSilent: false,bShrinkToFit: true});");
  exporter.exportReport();        
  return baos.toByteArray();
}
We are using code like this to export a PDF document from a Jasper application.
The line
exporter.setParameter(JRPdfExporterParameter.PDF_JAVASCRIPT, 
             "this.print({bUI: true,bSilent: false,bShrinkToFit: true});");
adds JavaScript to send the PDF document directly to the printer.
The expected behavior is that a print dialog will come up with a preview of the PDF document.
This works fine most of the time - except I am having problems about one out of every 5-6 times in Internet Explorer 8 and Firefox.
What happens is - the print preview dialog with the PDF document does not appear or it appears with a blank document in the preview window.
-I've tried a number of different JavaScripts (different params to this.print() via exporter.setParameter
-I've tried setting different response headers such as 
response.setContentType("application/pdf");
response.setHeader("Content-disposition","inline;  filename=\"" 
                   + reportName 
                   + "\"");
response.setContentLength(baos.size());
these did not seem to help
This seems to be an IE and FF issue. Has anyone ever dealt with this problem? I need to get it to work across all browsers 100% of the time. Perhaps a different approach to accomplish the goal of sending the PDF document export directly to the printer? or a third party library that will work across browsers?
© Programmers or respective owner